package cn.tedu.mall1.personal.controller;

import cn.tedu.mall1.base.response.JsonResult;
import cn.tedu.mall1.personal.pojo.dto.PersonalDTO;
import cn.tedu.mall1.personal.pojo.dto.PersonalOrderDTO;
import cn.tedu.mall1.personal.pojo.vo.PersonalV0;
import cn.tedu.mall1.personal.service.PersonalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/personal")
@Api(tags = "个人信息")
public class PersonalController {

    @Autowired
    private PersonalService personalService;

    @ApiOperation(value = "查询个人信息")
    @GetMapping("select")
    public JsonResult select(String username) {
        log.debug("入参名字：{}",username);
        PersonalV0 personalV0 = personalService.selectUser(username);
        log.debug("返回参数：{}",personalV0);
        return JsonResult.ok(personalV0);
    }

    @ApiOperation(value = "查询订单信息")
    @GetMapping("order")
    public JsonResult selectOrder(String username) {
        log.debug("入参名字：{}",username);
        List<PersonalOrderDTO> personalOrderDTO = personalService.selectOrder(username);
        log.debug("返回参数：{}",personalOrderDTO);
        return JsonResult.ok(personalOrderDTO);
    }

    @ApiOperation(value = "修改个人信息")
    @PostMapping("update")
    public JsonResult updatePersonal(PersonalDTO personalDTO) {
        log.debug("入参数据：{}",personalDTO);
        personalService.updatePersonal(personalDTO);
        return JsonResult.ok();
    }
}
